package com.hgts.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hgts.common.R;
import com.hgts.pojo.Book;
import com.hgts.pojo.Type;
import com.hgts.mapper.TypeMapper;
import com.hgts.service.ITypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 凡哥哥
 * @since 2023-04-27
 */
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type> implements ITypeService {

    @Autowired
    private ITypeService typeService;
    @Override
    public R<Page> pageInfo(int page, int pageSize, String name) {
        //分页构造器
        Page<Type> pageInfo = new Page(page,pageSize);
        //分页条件
        LambdaQueryWrapper<Type> lqw = new LambdaQueryWrapper();
        //获取的数据这个字段必须为0代表没有删除，可以查询；
        lqw.like(StringUtils.isNotEmpty(name),Type::getType,name);
        lqw.eq(Type::getIsDelete,0);
        return R.success(typeService.page(pageInfo,lqw));

    }
    //删除、批量删除
    @Override
    public R<String> deleteType(Integer... ids) {
        for (int id : ids) {
            LambdaUpdateWrapper<Type> lqw = new LambdaUpdateWrapper<>();
            //删除的数据必须等于当前的id
            lqw.eq(Type::getId,id);
            //进行伪删除把这个字段改为1就是删除
            lqw.set(Type::getIsDelete,1);
            this.update(lqw);

        }
        return R.success("图书信息修改成功");
    }
}
